package com.huawei.appgallery.datastorage.database;

import android.content.Context;
import androidx.annotation.NonNull;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import o.blw;
import o.blz;
import o.bma;
import o.bmb;
import o.bmd;
import o.bmg;

public abstract class AbsDataDAO {
    private static final Map<Class<? extends blz>, bma> ˊ = new ConcurrentHashMap();
    @NonNull
    private bma ˋ;
    @NonNull
    protected bmb ˏ;
    private blw ॱ = null;

    public static class TableInitExecption extends RuntimeException {
        public TableInitExecption(String str) {
            super(str);
        }
    }

    public AbsDataDAO(Context context, Class<? extends blz> cls, Class<? extends blw> cls2) {
        try {
            if (ˊ.containsKey(cls)) {
                this.ˋ = (bma) ˊ.get(cls);
            } else {
                this.ˋ = new bma(context, (blz) cls.getDeclaredConstructor(new Class[]{Context.class}).newInstance(new Object[]{context}));
                ˊ.put(cls, this.ˋ);
            }
        } catch (NoSuchMethodException e) {
            bmg.ˊ.ˏ("AbsDataDAO", "database failed:NoSuchMethodException");
        } catch (IllegalAccessException e2) {
            bmg.ˊ.ˏ("AbsDataDAO", "database failed:IllegalAccessException");
        } catch (InstantiationException e3) {
            bmg.ˊ.ˏ("AbsDataDAO", "database failed:InstantiationException");
        } catch (InvocationTargetException e4) {
            bmg.ˊ.ˏ("AbsDataDAO", "database failed:InvocationTargetException");
        }
        if (this.ˋ != null) {
            this.ॱ = bmd.ॱ(cls2);
        }
        if (this.ॱ == null) {
            throw new TableInitExecption("init table failed");
        }
        this.ˏ = new bmb(this.ˋ, this.ॱ.ˊ());
    }

    public void ॱ() {
        this.ˋ.ˎ();
    }

    public void ˏ() {
        this.ˋ.ॱ();
    }
}
